package com.kady.service.impl;

import com.kady.Dao.FoodTypeDao;
import com.kady.Dao.MenuDao;
import com.kady.contant.BeanFactoryConstant;
import com.kady.entity.Food;
import com.kady.entity.FoodType;
import com.kady.factory.BeanFactory;
import com.kady.service.FoodTypeService;

import java.sql.SQLException;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: kady
 * \* Date: 2021/3/24
 * \* Time: 21:08
 * \* 千峰JAVA2101班
 * \* Description: 菜系业务层IMPL
 * \
 */
public class FoodTypeServiceImpl implements FoodTypeService {
    private FoodTypeDao foodTypeDao = (FoodTypeDao)BeanFactory.getBean(BeanFactoryConstant.FOODTYPE_DAO);

    @Override
    public List<FoodType> getFoodTypeList(String keyword) throws SQLException {
        List<FoodType> res = foodTypeDao.selectFoodTypeList("%"+(keyword==null?"":keyword.trim())+"%");
        return res;
    }

    @Override
    public FoodType findOne(long typeId) throws SQLException {
        FoodType foodType = foodTypeDao.selectFoodType(typeId);
        return foodType;
    }

    @Override
    public void addFoodType(FoodType foodType) throws SQLException {
        foodTypeDao.saveFoodType(foodType.getTypeId(),foodType.getTypeName());
    }

    @Override
    public void updateFoodType(FoodType foodType) throws SQLException {
        foodTypeDao.updateFoodType(foodType.getTypeName(),foodType.getTypeId());
    }

    @Override
    public void removeFoodType(long typeId) throws SQLException {
        foodTypeDao.deleteFoodType(typeId);
    }

    @Override
    public FoodType getFoodTypeByName(String name) throws SQLException {
        FoodType res = foodTypeDao.selectFoodTypeByName(name);
        return res;
    }
}
